package labox.innovation.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import labox.innovation.util.L2Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NetcoreConfig {
    private static final Logger _log = LoggerFactory.getLogger(NetcoreConfig.class.getName());

    private static final String NETCORE_CONFIG_FILE = "./config/netcore.properties";

    // --------------------------------------------------
    // NetCore Settings
    // --------------------------------------------------
    public static int NETCORE_SELECTOR_SLEEP_TIME;

    public static int NETCORE_MAX_SEND_PER_PASS;

    public static int NETCORE_MAX_READ_PER_PASS;

    public static int NETCORE_HELPER_BUFFER_COUNT;

    public static void load() {
        _log.info("Loading netcore Configuration Files...", Config.SERVER_ID);
        InputStream is = null;
        try {
            L2Properties mmoSettings = new L2Properties();
            is = new FileInputStream(new File(NETCORE_CONFIG_FILE));
            mmoSettings.load(is);
            NETCORE_SELECTOR_SLEEP_TIME = Integer.parseInt(mmoSettings.getProperty("SleepTime", "10"));
            NETCORE_MAX_SEND_PER_PASS = Integer.parseInt(mmoSettings.getProperty("MaxSendPerPass", "10"));
            NETCORE_MAX_READ_PER_PASS = Integer.parseInt(mmoSettings.getProperty("MaxReadPerPass", "10"));
            NETCORE_HELPER_BUFFER_COUNT = Integer.parseInt(mmoSettings.getProperty("HelperBufferCount", "20"));
        } catch (Exception e) {
            _log.error("Failed to Load " + NETCORE_CONFIG_FILE + " File.", e);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                _log.error("InputStream close occured IOException");
            }
        }
    }
}
